﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Twinkle.URLShortener
{
    public static class URLShortenManager
    {
        public static IEnumerable<IURLCompressor> EnumerateCompressor()
        {
            yield return new Services.Bitly();
            yield return new Services.Jmp();
            yield return new Services.TinyURL();
        }

        public static bool IsCompressedThis(string url)
        {
            foreach (var c in EnumerateCompressor())
            {
                if (c.IsCompressed(url))
                    return true;
            }
            return false;
        }

        public static IURLCompressor GetSuggestedCompressor()
        {
            switch (Kernel.Config.External.URLShoteningService.Provider)
            {
                case Twinkle.Data.Config.ExternalConfig.URLShortenServiceDescriptor.URLShortenServiceProviders.bitly:
                    return new Services.Bitly();
                case Twinkle.Data.Config.ExternalConfig.URLShortenServiceDescriptor.URLShortenServiceProviders.jmp:
                    return new Services.Jmp();
                case Twinkle.Data.Config.ExternalConfig.URLShortenServiceDescriptor.URLShortenServiceProviders.TinyURL:
                    return new Services.TinyURL();
                default:
                    return null;
            }
        }
        
        public static IURLCompressor[] GetCompressors()
        {
            return new IURLCompressor[] { new Services.Bitly() };
        }

        public static IURLDecompressor[] GetDecompressors()
        {
            return new IURLDecompressor[] { new Services.Bitly(), new URLCommonDecompressor() };
        }
    }
}
